<template>
  <div>
    <h4>title id:{{id}}</h4>
    <p class="from">
      <i class="ctime">时间：2019-09-09</i>
      <em>来源：www.baidu.com</em>
      <span>作者：xxx</span>
    </p>
    <div class="main">
      <template v-for="(item,index) in article.text">
        <img :key="index" class="image" :src="item.context" v-if="item.type=='image'" alt />
        <p :key="index" class="subtetle" v-if="item.type=='subtetle'">{{item.context}}</p>
        <p :key="index" class="text" v-if="item.type=='text'">{{item.context}}</p>
        <p :key="index" class="code" v-if="item.type=='code'">{{item.context}}</p>
      </template>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      id: "",
      article: {
        title: "title",
        ctime: "2019-09-09",
        from: "www.baidu.com",
        owner: "xxx",
        text: [
          {
            type: "subtetle",
            context: "subtetle"
          },
          {
            type: "text",
            context: `我们在news文件夹下面新建了_id.vue的文件，以下划线为前缀的Vue文件就是
            动态路由，然后在文件里边有$route.params.id来接收参数我们在news文件夹下面新建了
            _id.vue的文件，以下划线为前缀的Vue文件就是动态路由，然后在文件里边有$route.params.id来接收参数`
          },
          {
            type: "image",
            context: `https://tpc.googlesyndication.com/simgad/3883678834175911542?
            sqp=4sqPyQQ_Qj0qNQhfEAEdAAC0QiABKAEwCTgDQPCTCUgAWAFgX3ACnQEAAIA_
            qAEBsAGAreIEuAFfxQEtsp0-OPCTCVAB&rs=AOga4qkPdSQQvZEC1XcEJJwKuytDaEQyGQ`
          },
          {
            type: "code",
            context: "www.baidu.com"
          },
          
          {
            type: "subtetle",
            context: "subtetle"
          },
          {
            type: "text",
            context: `我们在news文件夹下面新建了_id.vue的文件，以下划线为前缀的Vue文件就是
            动态路由，然后在文件里边有$route.params.id来接收参数我们在news文件夹下面新建了
            _id.vue的文件，以下划线为前缀的Vue文件就是动态路由，然后在文件里边有$route.params.id来接收参数`
          },
          {
            type: "image",
            context: `https://tpc.googlesyndication.com/simgad/3883678834175911542?
            sqp=4sqPyQQ_Qj0qNQhfEAEdAAC0QiABKAEwCTgDQPCTCUgAWAFgX3ACnQEAAIA_
            qAEBsAGAreIEuAFfxQEtsp0-OPCTCVAB&rs=AOga4qkPdSQQvZEC1XcEJJwKuytDaEQyGQ`
          },
          {
            type: "code",
            context: "www.baidu.com"
          }
        ]
      }
    };
  },
  mounted() {
    // console.log(this.$route.query.id);
    this.id = this.$route.query.id;
  }
};
</script>

<style lang="scss" scoped>
h4 {
  text-align: center;
  font-size: 1.6rem;
  margin-bottom: 0.5rem;
  margin-top: 1rem;
}
.from {
  font-size: 0.4rem;
  color: #666;
  margin-bottom: 1rem;
}
.main {
  .subtetle {
    font-size: 1.2rem;
    font-weight: 700;
    color: #666;
    margin-bottom: 0.5rem;
  }
  .text {
    text-indent: 2rem;
    font-size: 1rem;
    color: #444;
    line-height: 1.5rem;
    margin-bottom: 0.5rem;
  }
  .code {
    background-color: #999;
    color: #fff;
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 0.5rem;
  }
  .image {
    margin: 0 auto 0.5rem;
    display: block;
  }
}
</style>